#include <iostream>
#include <thread>

#include "ash_panel/panel.hpp"

bool should_exit = false;

void key_pressed_w() {
    std::cout << "move forward\n"
              << std::endl;
}
void key_pressed_s() {
    std::cout << "move backward\n"
              << std::endl;
}

void loop() {
    while (!should_exit) {
        ash_spin_once();
    }
}

void exit_ash() {
    should_exit = true;
}

void controller() {
    ash_init();
    ASH_EXPORT_KEY_BIND('q', exit_ash);
    ASH_EXPORT_KEY_BIND('w', key_pressed_w);
    ASH_EXPORT_KEY_BIND('s', key_pressed_s);
    ASH_EXPORT_KEY_BIND('a', []() { std::cout << "turn left\n"
                                              << std::endl; });
    ASH_EXPORT_KEY_BIND('d', []() { std::cout << "turn right\n"
                                              << std::endl; });
    ASH_EXPORT_CMD_BIND("start", [](int argc, char *argv[]) {
        std::cout << "Start engine." << std::endl;
    });
    ASH_EXPORT_CMD_BIND("help", [](int argc, char *argv[]) {
        std::cout << "--------------------" << std::endl;
        std::cout << "Press the keys as you want:" << std::endl;
        std::cout << "w: forward" << std::endl;
        std::cout << "a: turn left" << std::endl;
        std::cout << "s: backward" << std::endl;
        std::cout << "d: turn right" << std::endl;
        std::cout << "Enter commands as you want:" << std::endl;
        std::cout << "help: show help info" << std::endl;
        std::cout << "press Q or CTRL+C to exit." << std::endl;
        std::cout << "--------------------" << std::endl;
    })
    std::thread th(loop);
    th.join();
}

int main(int argc, char *argv[]) {
    controller();
    return 0;
}